import table from '@/components/dt/table/render.js'
import Opt from '@/components/dt/info/Opt.js'

let _this = null

class Column extends Opt {
  constructor(vm) {
    super()
    _this = vm
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }

  createAll() {
    this.all = [
      {
        title: '所属事业部',
        field: 'caseLocation',
        minWidth: 150
      },
      {
        title: '所属子公司',
        field: 'caseLocationTwo',
        minWidth: 150
      },
      {
        title: '所属事业处',
        field: 'department',
        minWidth: 150
      },
      {
        title: '所属案场',
        field: 'buildingName',
        minWidth: 150
      },
      {
        field: 'releaseChannel',
        minWidth: 150,
        header: {
          filter: {
            title: '投放渠道',
            key: 'releaseChannel',
            placeholder: '请选择投放渠道',
            select: {
              options: [
                { key: '3', value: '全部' },
                { key: '1', value: '同策好房' },
                { key: '2', value: '百度地图' }
              ]
            },
            data: {
              to: (v) => {
                return {
                  bdFlag: v.value == 2,
                  hfFlag: v.value == 1
                }
              }
            }
          }
        },
        slots: {
          default: (params, h) => {
            let releaseChannelText = []
            params.row.hfFlag == 1 ? releaseChannelText.push('同策好房') : null
            params.row.bdFlag == 1 ? releaseChannelText.push('百度地图') : null
            return [h('div', releaseChannelText.join(','))]
          }
        }
      },
      {
        title: '案场呼入号个数',
        field: 'caseInCount',
        minWidth: 150
      },
      {
        title: '承接中顾问个数',
        field: 'adviserCount',
        minWidth: 150
      },
      {
        title: '操作',
        fixed: 'right',
        minWidth: 460,
        align: 'center',
        slots: {
          default: (params, h) => {
            let btns = [
              {
                title: _this.unlocking('0213090200') ? '配置案场' : '',
                event: 'receiveCase',
                data: params.row
              },
              {
                title: `${
                  _this.unlocking('0213090300') && (params.row.bdFlag || params.row.hfFlag)
                    ? '配置案场呼入号'
                    : ''
                }`,
                event: 'receiveCallIn',
                data: params.row
              },
              {
                title: _this.unlocking('0213090500') ? '配置承接人' : '',
                event: 'acceptor',
                data: params.row
              },
              {
                title: _this.unlocking('0213090400') ? '承接人详情' : '',
                event: 'acceptorDetail',
                data: params.row
              },
              {
                title: _this.unlocking('0213090600') ? '导出案场承接人' : '',
                event: 'exportAcceptor',
                data: params.row
              }
            ]
            return table.cell.btns(_this, h, btns)
          }
        }
      }
    ]
  }
}

export default Column
